test(handlers): drive auth/cli_auth/magic_link to ≥95% coverage#157
Open
mastermanas805 wants to merge 2 commits into
Open
test(handlers): drive auth/cli_auth/magic_link to ≥95% coverage#157mastermanas805 wants to merge 2 commits into
mastermanas805 wants to merge 2 commits into
Conversation
Covers the login/me/refresh/logout, OAuth (GitHub/Google + browser callbacks), CLI device-flow, and magic-link Start/Callback paths. Adds source seams that keep behaviour unchanged in prod: - OAuth provider endpoint URLs become package vars repointable at an httptest server (SetOAuthURLsForTest) so the full exchange → find-or-create-user → mint-JWT path runs against a fake provider. - PersistMagicLinkSendStatusForTest re-exports the unexported persist helper so its two log-and-swallow error branches are reachable. New error/branch coverage via deterministic fault injection (isolated per-test DB with DROP TABLE / CHECK constraint tricks, a concurrent single-use consume race, and direct helper calls): - GitHub/Google browser-callback exchange + userinfo failures - findOrCreateUserGitHub/Google new-user markEmailVerified + link errors - FindOrCreateUserByEmail empty-local-part teamName fallback - magic-link persist-status both error arms + the consume-race (!consumed) branch Final per-file: auth.go 95.33%, cli_auth.go 95.56%, magic_link.go 95.15%. The 3 residual uncovered magic_link.go blocks are genuinely unreachable without rand/redis-internal fault injection (pipe.Exec returns the cmd error before Result is read; rand.Read never fails; HMAC sign never errors on a valid []byte key) and are documented inline. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
internal/handlersto ≥95% statement coverage: auth.go 95.33%, cli_auth.go 95.56%, magic_link.go 95.15% (login/me/refresh/logout, OAuth GitHub/Google + browser callbacks, CLI device-flow, magic-link Start/Callback).SetOAuthURLsForTest);PersistMagicLinkSendStatusForTestre-exports the unexported persist helper to reach its log-and-swallow error arms.DROP TABLE/CHECKconstraint), a concurrent single-use consume race for the!consumedbranch, and direct helper calls: OAuth browser-callback exchange/userinfo failures, find-or-create new-usermarkEmailVerified+ link errors,FindOrCreateUserByEmailempty-local-part teamName fallback, magic-link persist-status both error arms.The 3 residual uncovered
magic_link.goblocks are genuinely unreachable without rand/redis-internal fault injection (pipelineExecsurfaces the command error beforeResult()is read;rand.Readnever fails; HMAC sign never errors on a valid[]bytekey) and are documented inline.Test plan
-p 1:go test ./internal/handlers -run 'TestAuth|TestCLI|TestMagicLink|TestLogin|TestRefresh|TestLogout' -count=1 -p 1pg_classmigration-race artifacts in unrelated billing/db/nosql/storage/deploy tests (pass cleanly against a fresh Redis, which CI uses)make gate) green